home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
st80_pr4.lha
/
st80_pre4
/
MoDE
/
TrackingReplay-Shan.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
12KB
|
434 lines
EventQueue subclass: #TREventQueue
instanceVariableNames: 'trackingOrReplay rootModeOrg storage lastmsec '
classVariableNames: ''
poolDictionaries: ''
category: 'TrackingReplay-Shan'!
TREventQueue comment:
'This is the event queue used for replay. Shan 16 July 1990'!
!TREventQueue methodsFor: 'control'!
disable
"Shan 18 July 1990"
trackingOrReplay == #replay
ifTrue: [^self]
ifFalse: [super disable]!
enable
"Shan 18 July 1990"
trackingOrReplay == #replay
ifTrue: [^self]
ifFalse: [super enable]!
terminateTracking
"Shan 18 July 1990"
trackingOrReplay == #tracking ifTrue: [storage close].
trackingOrReplay _ nil! !
!TREventQueue methodsFor: 'access'!
nextPut: value
"The time kept in the msec is relative. It is defined as T(previous
event) - T(current event). Shan 18 July 1990"
| overflow newmsec interval storedEvent |
overflow _ false.
accessProtect critical: [contents size > Limit
ifTrue:
["contents _ OrderedCollection new. Transcript show:
'Event queue overflow\' withCRs Shan 11 June 1990"
overflow _ true.
self init: contents size]
ifFalse: [contents addLast: value]].
overflow
ifFalse:
[readSynch signal.
"Added stuffs begin here. Shan 18 July 1990"
trackingOrReplay == #tracking
ifTrue:
[storedEvent _ value deepCopy.
newmsec _ Time millisecondClockValue.
lastmsec isNil
ifTrue:
[lastmsec _ 0.
interval _ 0]
ifFalse: [interval _ newmsec - lastmsec].
storedEvent msec: interval.
lastmsec _ newmsec.
storedEvent origin: value origin - rootModeOrg.
storedEvent previousOrigin: value previousOrigin - rootModeOrg.
storage nextPut: storedEvent].
trackingOrReplay == #replay
ifTrue:
["Adjust the coordinates."
value origin: value origin + rootModeOrg.
value previousOrigin: value previousOrigin + rootModeOrg]].
last _ value deepCopy.
^value!
rootModeOrigin
"Shan 18 July 1990"
^rootModeOrg!
rootModeOrigin: pt
"Shan 18 July 1990"
rootModeOrg _ pt!
storage
"Shan 18 July 1990"
^storage!
storage: s
"Shan 18 July 1990"
storage _ s!
trackingOrReplay
"This can be of values #tracking or #replay. Shan 18 July 1990"
^trackingOrReplay!
trackingOrReplay: tOrR
"This can be of values #tracking or #replay. Shan 18 July 1990"
trackingOrReplay _ tOrR! !
SNATextController subclass: #SNATextControllerEd
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'TrackingReplay-Shan'!
!SNATextControllerEd methodsFor: 'basic control sequence'!
controlLoop
"Combine the controlLoop and the controlActivity. Shan 18 July 1990"
| event eq |
eq _ self eventQueue.
eq enable.
[self isControlActive]
whileTrue:
[event _ eq next.
(self scrollBarContainsCursor: event)
ifTrue: [self scroll: event]
ifFalse: [event selector == #keyboardEvent
ifTrue: [self readKeyboard: event]
ifFalse: [self processMouseButtons: event]]].
eq disable! !
!SNATextControllerEd methodsFor: 'event driven'!
processMouseButtons: e
"Shan 15 July 1990"
e leftButtonDown ifTrue: [self processRedButton: e].
e middleButtonDown
ifTrue:
[self eventQueue disable.
self processYellowButton.
self eventQueue enable].
e rightButtonDown ifTrue: [self processBlueButton]!
processRedButton: e
"This is a simple one. Does not handle drag and double click. Shan 15 July 1990"
| selectionBlocks block |
self deselect.
self closeTypeIn.
block _ paragraph characterBlockAtPoint: e origin.
paragraph displayCaretForBlock: block.
selectionBlocks _ Array with: block with: block.
selectionShowing _ true.
startBlock _ selectionBlocks at: 1.
stopBlock _ selectionBlocks at: 2.
self updateMarker.
self setEmphasisHere!
readKeyboard: e
"Shan 30 June 1990"
| typeAhead currentCharacter mEvent |
self deselect.
typeAhead _ WriteStream on: (String new: 128).
beginTypeInBlock == nil
ifTrue:
[UndoSelection _ self selection.
beginTypeInBlock _ startBlock copy].
mEvent _ e.
[CurrentEvent _ mEvent keyboardEvent.
currentCharacter _ CurrentEvent keyCharacter.
(self
perform: (Keyboard at: currentCharacter asciiValue + 1)
with: typeAhead
with: currentCharacter)
ifTrue: [^self].
mEvent _ self eventQueue peek.
(mEvent notNil and: [mEvent selector == #keyboardEvent])
ifTrue:
[self eventQueue next.
true]
ifFalse: [false]] whileTrue.
self replaceSelectionWith: (Text string: typeAhead contents emphasis: emphasisHere).
startBlock _ stopBlock copy.
self selectAndScroll!
scroll: e
"Shan 1 July 1990"
| savedCursor regionPercent mEvent eq |
"self yellowMenuContainsCursor
ifTrue: [^self yellowMenuActivity]."
savedCursor _ sensor currentCursor.
eq _ self eventQueue.
mEvent _ e.
[self scrollBarOnlyArea containsPoint: mEvent origin]
whileTrue:
[Processor yield. "Shan 15 July 1990"
regionPercent _ 100 * (mEvent origin x - scrollBar left) // scrollBar width.
regionPercent <= 40
ifTrue: [self scrollDownEd: mEvent]
ifFalse: [regionPercent >= 60
ifTrue: [self scrollUpEd: mEvent]
ifFalse: [self scrollAbsoluteEd: mEvent]].
mEvent _ eq nextWithCursorMoveCompressed. "Shan 16 July 1990"].
savedCursor show!
scrollAbsoluteEd: e
| oldMarker delta newMarkerRegion oldCursorY cursorY offsetY eq mEvent |
self changeCursor: Cursor marker.
oldCursorY _ marker center y.
eq _ self eventQueue. "Shan 16 July 1990"
mEvent _ e.
self canScroll & e anyButtonDown ifTrue:
[[mEvent anyButtonDown] whileTrue:
[oldMarker _ marker copy.
cursorY _ mEvent origin y.
delta _ ((marker center y - cursorY) asFloat / self scrollBarOnlyArea height asFloat
* (paragraph textSize max: 1) asFloat) truncated.
(oldCursorY - cursorY) * delta <= 0 ifTrue: [delta _ 0].
self scrollView: delta.
oldCursorY _ cursorY.
newMarkerRegion _ self computeMarkerRegion.
offsetY _ (((paragraph lines at: 1) - 1) asFloat
/ (paragraph textSize max: 1) asFloat
* self scrollBarOnlyArea height asFloat) rounded
min: self scrollBarOnlyArea height - newMarkerRegion height.
marker region: (marker left@(self scrollBarOnlyArea top + offsetY) extent: newMarkerRegion corner).
(oldMarker areasOutside: marker), (marker areasOutside: oldMarker) do:
[:region | Display fill: region rule: Form reverse mask: Form gray].
mEvent _ eq nextWithCursorMoveCompressed].
self displayScrollBar.
self moveMarker]!
scrollBarContainsCursor: e
"Shan 30 June 1990"
^scrollBar containsPoint: e origin!
scrollDownEd: e
"Use the name 'scrollDownEd' to avoid confusion with other
implementations of 'scrollDown:'. Shan 15 July 1990"
self changeCursor: Cursor down.
e anyButtonDown ifTrue: [self canScroll
ifTrue:
[self scrollViewDown.
self updateMarker]].
self eventQueue waitNoButton!
scrollUp: e
"Shan 15 July 1990"
self changeCursor: Cursor up.
e anyButtonDown ifTrue: [self canScroll
ifTrue:
[self scrollViewUp.
self updateMarker]].
self eventQueue waitNoButton!
scrollUpEd: e
"Use the name 'scrollUpEd' to avoid confusion with other
implementations of 'scrollUp:'. Shan 15 July 1990"
self changeCursor: Cursor up.
e anyButtonDown ifTrue: [self canScroll
ifTrue:
[self scrollViewUp.
self updateMarker]].
self eventQueue waitNoButton! !
!SNATextControllerEd methodsFor: 'control defaults'!
controlActivity
"See if I can make it event-driven. Shan 30 June 1990"
| event |
event _ self eventQueue next.
(self scrollBarContainsCursor: event)
ifTrue: [self scroll: event]
ifFalse: [event selector == #keyboardEvent
ifTrue: [self readKeyboard: event]
ifFalse: [self processMouseButtons: event]]!
isControlActive
"Collapse all methods defined in the superclasses. Shan 18 July 1990"
| eq |
eq _ self eventQueue.
^wantControl & eq rightButtonDown not & ((view containsPoint: eq mousePoint)
| (scrollBar containsPoint: eq mousePoint))! !
!SNATextControllerEd methodsFor: 'tracking/replay'!
eventQueue
"Shan 15 July 1990"
^view topView controller eventQueue! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
SNATextControllerEd class
instanceVariableNames: ''!
!SNATextControllerEd class methodsFor: 'testing'!
editorTrackingtest
"Shan 18 July 1990"
"(RootMode new addSubMode: self editorTrackingtest) startUp"
| pView aPollingEnvMode w rMode |
rMode _ ExpandedMode new.
pView _ SNATextView
on: (SNAText fileName: 'temp')
aspect: #text
change: #acceptText:from:
menu: #textMenu.
pView controller: SNATextControllerEd new.
pView borderWidth: (1 @ 1 corner: 1 @ 1). "Shan March 21, 1990"
aPollingEnvMode _ PollingEnvMode new.
aPollingEnvMode addSubView: pView.
w _ SNATextWindow new.
w applicationMode: aPollingEnvMode.
w mode extent: 150 @ 150.
w initialOpen.
rMode addSubMode: w mode at: 40@40.
^rMode resizeStyle: ResizeStyle stickFourCorners!
test
"Shan 1 July 1990"
"self test"
| pView aPollingEnvMode w rMode |
rMode _ RootMode new.
pView _ SNATextView
on: (SNAText fileName: 'temp')
aspect: #text
change: #acceptText:from:
menu: #textMenu.
pView controller: SNATextControllerEd new.
pView borderWidth: (1 @ 1 corner: 1 @ 1). "Shan March 21, 1990"
aPollingEnvMode _ PollingEnvMode new.
aPollingEnvMode addSubView: pView.
w _ SNATextWindow new.
w applicationMode: aPollingEnvMode.
w mode extent: 150 @ 150.
w initialOpen.
rMode addSubMode: w mode.
rMode startUp! !
Object subclass: #TrackReplay
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'TrackingReplay-Shan'!
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
TrackReplay class
instanceVariableNames: ''!
!TrackReplay class methodsFor: 'track and replay'!
replay3
"Shan 18 July 1990"
"self replay3"
| aFileName fstorage event replayQueue rmode |
aFileName := 't'.
fstorage _ BinaryStorage read: aFileName asFilename readStream.
rmode _ RootMode new addSubMode: TestExamples oddShapeAndAnimationTest.
replayQueue _ TREventQueue new.
replayQueue trackingOrReplay: #replay.
rmode eventQueue: replayQueue.
[[fstorage atEnd]
whileFalse:
[event _ fstorage next.
(Delay forMilliseconds: event msec) wait.
replayQueue nextPut: event]] fork.
rmode startUp!
replay4
"Shan 18 July 1990"
"self replay4"
| trackfile fstorage event replayQueue rmode |
trackfile := FillInTheBlank request: 'File name for tracking ' initialAnswer: ''.
fstorage _ BinaryStorage read: trackfile asFilename readStream.
rmode _ RootMode new addSubMode: SNATextControllerEd editorTrackingtest.
replayQueue _ TREventQueue new.
replayQueue trackingOrReplay: #replay.
rmode eventQueue: replayQueue.
[[fstorage atEnd]
whileFalse:
[event _ fstorage next.
(Delay forMilliseconds: event msec) wait.
replayQueue nextPut: event].
rmode stopRunning] fork.
rmode startUp!
tracking3
"Shan 18 July 1990"
"self tracking3"
| trackfile storage rmode |
"trackfile := FillInTheBlank request: 'File name for tracking ' initialAnswer: ''.
trackfile asFilename exists
ifTrue:
[(self confirm: 'File already exists. Proceed to overwrite?')
ifFalse: [^self]]."
storage _ BinaryStorage write: "trackfile" 't' asFilename writeStream.
rmode _ RootMode new addSubMode: TestExamples oddShapeAndAnimationTest.
EventQ _ TREventQueue new.
EventQ trackingOrReplay: #tracking.
EventQ storage: storage.
rmode eventQueue: EventQ.
rmode startUp!
tracking4
"Shan 18 July 1990"
"self tracking4"
| trackfile storage rmode |
trackfile := FillInTheBlank request: 'File name for tracking ' initialAnswer: ''.
trackfile asFilename exists
ifTrue:
[(self confirm: 'File already exists. Proceed to overwrite?')
ifFalse: [^self]].
storage _ BinaryStorage write: trackfile asFilename writeStream.
rmode _ RootMode new addSubMode: SNATextControllerEd editorTrackingtest.
EventQ _ TREventQueue new.
EventQ trackingOrReplay: #tracking.
EventQ storage: storage.
rmode eventQueue: EventQ.
rmode startUp! !